package net.zoneland.knowledge.utils;

import org.apache.poi.ss.usermodel.*;

/**
 * 自定义列样式.
 * @author zx
 */
public class CellStyleUtil {

    public static CellStyle getHeaderStyle(final Workbook book) {
        final CellStyle headWriteCellStyle = book.createCellStyle();
        //设置水平居中
        headWriteCellStyle.setAlignment(HorizontalAlignment.CENTER);
        //设置垂直居中
        headWriteCellStyle.setVerticalAlignment(VerticalAlignment.CENTER);
        //设置边框为细边框，并且颜色为黑色
        headWriteCellStyle.setBorderBottom(BorderStyle.THIN);
        headWriteCellStyle.setBottomBorderColor((short)8);
        // 背景色与填充
        headWriteCellStyle.setFillForegroundColor((short)22);
        headWriteCellStyle.setFillPattern(FillPatternType.SOLID_FOREGROUND);

        //字体大小为12
        final Font font = book.createFont();
        font.setFontHeightInPoints((short)10);
        headWriteCellStyle.setFont(font);
        return headWriteCellStyle;
    }

    public static CellStyle getContentStyle(final Workbook book) {
        final CellStyle cellStyle = book.createCellStyle();
        //设置水平居中
        cellStyle.setAlignment(HorizontalAlignment.CENTER);
        //设置垂直居中
        cellStyle.setVerticalAlignment(VerticalAlignment.CENTER);
        //设置内容超出自动换行
        cellStyle.setWrapText(true);
        //设置字体不加粗，字体大小为12
        final Font font = book.createFont();
        font.setBold(false);
        font.setFontHeightInPoints((short)8);
        cellStyle.setFont(font);
        return cellStyle;
    }
}
